<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片切换完整版</title>
</head>
<body>
    <div id="box">
        <ul>
            <li class="item">
                <img src="images/pic1.jpg">
            </li>
            <li class="item">
                <img src="images/pic2.jpg">
            </li>
            <li class="item">
                <img src="images/pic3.jpg">
            </li>
            <li class="item">
                <img src="images/pic4.jpg">
            </li>
            <li class="item">
                <img src="images/pic5.jpg">
            </li>
        </ul>
    </div>
    <script type="text/javascript">
        // 1.获取事件源
        function $(id){
            return typeof id === 'string' ? document.getElementById(id) : null;
        }
        console.log($('box'));
        var items = document.getElementsByClassName('item');
        for(var i = 0; i < items.length; i++){
            var item = items[i];
            item.index = i+1;
            items[i].onmouseover = function(){
                console.log(this.id);
                $('box').style.background = `url('images/big_pic${this.index}.jpg') no-repeat;`
            }
        }
    </script>
</body>
</html>